package cloud.luyi.springcloud.controller;

import cloud.luyi.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 卢意
 * @create 2020-10-25 15:46
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixController {
	@Resource
	private PaymentHystrixService paymentHystrixService;

	@GetMapping("/consumer/hystrix/ok/{id}")
	public String paymentInfo_ok(@PathVariable(value = "id") Integer id){
		String result= paymentHystrixService.paymentInfo_ok(id);
		return result;
	}


	@GetMapping("/consumer/hystrix/timeout/{id}")
	/*@HystrixCommand(fallbackMethod = "paymentTimeOutFallBackMethod",commandProperties = {
			@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="2000")
	})*/
	@HystrixCommand //调用默认fallback方法
	public String paymentInfo_timeout(@PathVariable(value = "id") Integer id){
		String result= paymentHystrixService.paymentInfo_timeout(id);
		return result;
	}

	public String paymentTimeOutFallBackMethod(Integer id){
		return "我是消费者80,支付系统繁忙,请稍后重试 o(╥﹏╥)o";
	}

	//下面是全局 fallback 方法
	public String payment_Global_FallbackMethod(){
		return "Global异常处理信息,请稍后再试, (꒦_꒦) ";
	}
}
